<?php

namespace App\Http\Controllers\API;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class Login extends Controller
{
    //
    public function __construct(){
    	$this->permission = new \App\model\login();
    }

    public function login(Request $request)
    {
    	$post = $request->all();
    	if (!isset($post['account'])) {
    		$error['reason'] = 'There\'s no account for login';
    		return $error['code'] = 1;
    	}elseif (!isset($post['password'])) {
    		$error['reason'] = 'There\'s no password for login';
    		return $error['code'] = 1;
    	}else{
    		$selfPermission = $this->permission->login($post);
    		if ($selfPermission == 0) {
    			$resoult['code'] = 0;
    			$resoult['success'] = 0;
    		}else{
    			$resoult['code'] = 0;
    			$resoult['success'] = 1;
    		}
            $resoult = json_encode($resoult);
    		return $resoult;
    	}
    }
}
